package com.conversationboard.controller.sockpuppet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.conversationboard.model.User;
import com.conversationboard.model.sockpuppets.Sockpuppet;
import com.conversationboard.model.sockpuppets.SockpuppetSearchType;
import com.conversationboard.model.sockpuppets.Sockpuppets;

@WebServlet(name = "AdminSockpuppetReportServlet", urlPatterns = "/Admin/AdminSockpuppetReportServlet")
public class AdminSockpuppetReportServlet extends HttpServlet {

	private static final long serialVersionUID = 4874587891437077159L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		try {

			User user = User.get(request.getUserPrincipal().getName());

			if (!user.isSiteAdmin()) {
				return;
			}

			request.setCharacterEncoding("UTF-8");
			response.setCharacterEncoding("UTF-8");

			List<List<Sockpuppet>> passwordSockpuppets = Sockpuppets.getSockpuppets(SockpuppetSearchType.PASSWORD);
			/*
			 * List<List<Sockpuppet>> ipAddressSockpuppets =
			 * Sockpuppets.getSockpuppets(SockpuppetSearchType.IPADDRESS);
			 */

			request.setAttribute("passwordSockpuppets", passwordSockpuppets);
			/*
			 * request.setAttribute("ipAddressSockpuppets",
			 * ipAddressSockpuppets);
			 */

			RequestDispatcher dispatcher = request.getRequestDispatcher("/Pages/Admin/view-sockpuppet-report.jsp");
			dispatcher.forward(request, response);

		} catch (SQLException e) {
			throw new ServletException(e);
		}

	}
}
